//
//  OrderGoodsInfo.m
//
//  Created by   on 2019/2/26
//  Copyright (c) 2019 __MyCompanyName__. All rights reserved.
//

#import "OrderGoodsInfo.h"


NSString *const kOrderGoodsInfoName = @"name";
NSString *const kOrderGoodsInfoImg = @"img";


@interface OrderGoodsInfo ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation OrderGoodsInfo

@synthesize name = _name;
@synthesize img = _img;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict {
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if (self && [dict isKindOfClass:[NSDictionary class]]) {
            self.name = [self objectOrNilForKey:kOrderGoodsInfoName fromDictionary:dict];
            self.img = [self objectOrNilForKey:kOrderGoodsInfoImg fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation {
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.name forKey:kOrderGoodsInfoName];
    [mutableDict setValue:self.img forKey:kOrderGoodsInfoImg];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description  {
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super init];

    self.name = [aDecoder decodeObjectForKey:kOrderGoodsInfoName];
    self.img = [aDecoder decodeObjectForKey:kOrderGoodsInfoImg];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_name forKey:kOrderGoodsInfoName];
    [aCoder encodeObject:_img forKey:kOrderGoodsInfoImg];
}

- (id)copyWithZone:(NSZone *)zone {
    OrderGoodsInfo *copy = [[OrderGoodsInfo alloc] init];
    
    
    
    if (copy) {

        copy.name = [self.name copyWithZone:zone];
        copy.img = [self.img copyWithZone:zone];
    }
    
    return copy;
}


@end
